package com.open.api.wechat.config;

import com.open.api.wechat.config.properties.WeChatAppProperties;
import com.open.api.wechat.app.WeChatAppService;
import com.open.api.wechat.app.impl.WeChatAppServiceImpl;
import com.open.api.wechat.config.condition.WeChatAppCondition;
import com.open.api.wechat.config.condition.WeChatPubCondition;
import com.open.api.wechat.config.properties.WeChatPubProperties;
import com.open.api.wechat.pub.WeChatPubService;
import com.open.api.wechat.pub.impl.WeChatPubServiceImpl;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;

/**
 * @author : zhaoxuan
 * @version : 1.0
 * @date : 2021/6/25 0:05
 * @description : AppAutoConfig
 */
@Data
@AllArgsConstructor
@EnableConfigurationProperties({WeChatAppProperties.class, WeChatPubProperties.class})
public class WeChatAutoConfiguration {

    private final WeChatAppProperties weChatAppProperties;

    private final WeChatPubProperties weChatPubProperties;

    @Bean
    @Conditional(WeChatAppCondition.class)
    @ConditionalOnMissingBean(WeChatAppService.class)
    public WeChatAppService weChatAppService(){
        return new WeChatAppServiceImpl(weChatAppProperties);
    }

    @Bean
    @Conditional(WeChatPubCondition.class)
    @ConditionalOnMissingBean(WeChatPubService.class)
    public WeChatPubService weChatPubService(){
        return new WeChatPubServiceImpl(weChatPubProperties);
    }
}
